import java.util.ArrayList;
import java.util.List;

public class SoilNutrientSensor {
    private final List<SensorObserver> observers = new ArrayList<>();
    private double nutrientContent = 50.0; // 默认养分含量

    public void addObserver(SensorObserver observer) {
        observers.add(observer);
    }

    public void setNutrientContent(double nutrientContent) {
        this.nutrientContent = nutrientContent;
        notifyObservers();
    }

    private void notifyObservers() {
        for (SensorObserver observer : observers) {
            observer.updateNutrient(nutrientContent);
        }
    }

    public double getNutrientContent() {
        return nutrientContent;
    }
}
